package cn.ywang.client;

import java.lang.reflect.Proxy;

/**
 * @Auther: BeatificWang
 * @Date: 2018/11/25 23:27
 */
public class RpcClientProxy {

	/**
	 * 创建客户端的远程代理
	 *
	 * @param interfaceCls
	 * @param host
	 * @param port
	 * @param <T>
	 * @return
	 */
	public <T> T clientProxy(final Class<T> interfaceCls,
	                         final String host, final int port) {
		//使用到了动态代理
		return (T) Proxy.newProxyInstance(interfaceCls.getClassLoader(),
		                                  new Class[]{interfaceCls},
		                                  new RemoteInvocationHandler(host, port));
	}
}
